#pragma once

#include "IXSystemService.h"
#include "XBaseObjImpl.h"
#include "XLock.h"

#include <list>

class CXSystemServiceImpl : public CXBaseObjImpl<IXSystemService>
{
    typedef CXBaseObjImpl<IXSystemService> superclass;
    DEF_SKIN_CLASS_SINGLE_INTF(CXSystemServiceImpl,
        superclass,
        gs_strGuidXSkin,
        IXSystemService,
        eIntf_Singleton);
public:
    CXSystemServiceImpl();
    virtual ~CXSystemServiceImpl();

public:
    // IXSystemService
    virtual HRESULT STDMETHODCALLTYPE   ExecProgram(IN eSysExecType eType, IN LPCTSTR szFile, IN LPCTSTR szParams);

public:
    // IBaseObj
    virtual void STDMETHODCALLTYPE  OnFinalRelease();

protected:

    // ExecProgram
    typedef struct  
    {
        eSysExecType eType;
        XString      strFile;
        XString      strParams;
    } ExeProgData;
    typedef std::list<ExeProgData> ExeProgDataContainter;
    ExeProgDataContainter   m_ExeProgDataContainter;

    XLockSection     m_DataLock;

    HANDLE           m_hThread;
    BOOL             m_bStop;
    XLockEvent       m_ThreadLock;

    static unsigned WINAPI ExecProgramThread(void* pParam);
    unsigned        ExecProgramProc();

};

